/**
 * Time is used to denote a time in 24 hours using hour and mintute as
 * integers. Correct formatting of numbers, h: 0 - 23, m: 0 - 59, must be
 * checked before creating object
 */
public class Time implements Comparable<Object>
{
    private int hour;
    private int minute;

    /**
     * Time doesn't have the empty contructor and so can only be created
     * with entries for hour and minute.
     * 
     * @param h hour
     * @param m minute
     */
    public Time(int h, int m)
    {
        hour = h;
        minute = m;
    }

    /**
     * Returns hour.
     */
    public int getHour()
    {
        return hour;
    }

    /**
     * Returns minute.
     */
    public int getMinute()
    {
        return minute;
    }

    /**
     * Checks whether t is before or equal to this object.
     * e.g. t1.before(t2) is the same as t1 <= t2
     * 
     * @param t time checked with current object
     * 
     * @return Returns true if t is before or equal to the current time,
     * otherwise false
     */
    public boolean before(Time t)
    {
        boolean check = false;

        if(this.compareTo(t) == -1 || this.compareTo(t) == 0)
        {
            check = true;
        }

        return check;
    }

    /**
     * Checks whether t is after or equal to this object.
     * e.g. t1.after(t2) is the same as t1 >= t2
     * 
     * @param t time checked with current object
     * 
     * @return true if t is after or equal to the current time,
     * otherwise false
     */
    public boolean after(Time t)
    {
        boolean check = false;

        if(this.compareTo(t) == 1 || this.compareTo(t) == 0)
        {
            check = true;
        }

        return check;
    }

    /**
     * Returns Time in format h:m
     */
    public String toString()
    {
        return (hour + ":" + minute);
    }

    /** 
     * Used to compare Times.
     * 
     * @return -1,0,1 when Time o is before, equal to or after this object
     */
    public int compareTo(Object o) throws ClassCastException
    {
        int value = 0;

        if(o instanceof Time)
        {
            Time time = (Time) o;
            int hour1 = hour;
            int hour2 = time.getHour();
            int minute1 = minute;
            int minute2 = time.getMinute();

            if((hour1 == hour2 && minute1 > minute2) || (hour1 > hour2))
            {
                value = 1;
            }
            if((hour1 == hour2 && minute1 < minute2) || (hour1 < hour2))
            {
                value = -1;
            }
        }

        return value;
    }
}
